﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Modelo;

namespace Interface
{
    /// <summary>
    /// Interaction logic for EditarCliente.xaml
    /// </summary>
    public partial class EditarCliente : Window
    {
        public EditarCliente(Cliente cliente)
        {
            InitializeComponent();
            txbxCI.Text = cliente.CI.ToString();
            txbxApellido.Text = cliente.Apellido.ToString();
            txbxDireccion.Text = cliente.Direccion.ToString() ;
            txbxTelefono.Text = cliente.Telefono.ToString();
        }

        private void txbxApellido_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                Proceso.GestorCliente.VerificarNombre(txbxApellido.Text);
                lblErrorAp.Content = " ";
            }
            catch (Exception es)
            {

                lblErrorAp.Content = es.Message;
            }
        }

        private void txbxDireccion_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                Proceso.GestorCliente.VerificarDireccion(txbxDireccion.Text);
                lblErrorDir.Content = " ";
            }
            catch (Exception ex)
            {
                lblErrorDir.Content = ex.Message;
                
            }
        }

        private void txbxTelefono_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                Proceso.GestorCliente.VerificarTelefono(txbxTelefono.Text);
                lblErrorTel.Content = "";
            }
            catch (Exception)
            {

                lblErrorTel.Content = " ";
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Proceso.GestorCliente.ModificarCliente(txbxCI.Text, txbxTelefono.Text, txbxApellido.Text, txbxDireccion.Text);
                MessageBox.Show("Cliente modificado exitosamente");
                this.Close();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
